import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Http, Response } from '@angular/http';
import { map } from "rxjs/operators";
@Injectable()
export class ConfigService {

    constructor(private http: HttpClient) { }

    /** 获取全部配置项 */
    list() {
        return this.http.get('/system/api/config/list').pipe(
            map((res: Response) => res['data'])
        );
    }

    /**显示新增/编辑界面 */
    showDetail(configKey: string) {
        return this.http.get('/system/api/config/load?configKey=' + configKey).pipe(
            map((res: Response) => res['data'])
        );
    }

    /**保存或更新配置项 */
    saveUpdateConfig(config: any) {
        return this.http.post('/system/api/config/saveupdate', config).pipe(
            map((res: Response) => res['data'])
        );
    }

    /**移除配置项目 */
    delete(configKey: string) {
        return this.http.get('/system/api/config/delete?configKey=' + configKey).pipe(
            map((res: Response) => res['data'])
        );
    }

}